<?php


namespace App\Service\common;


use App\Common\Res;
use App\Constants\ConstCode;
use App\Constants\ErrorCode;
use App\Service\api\messageService;
use App\Service\api\operationService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class chartSwitchService
{
    use Res;

    /**
     *解析传输类型
     * @param int $fd
     * @return array
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function getChartSwitchService(int $fd, $string): array
    {
        var_dump($string);
        if (!empty($string)) {
            $dataArr = json_decode($string, true);
            if (!empty($dataArr) && isset($dataArr['commandType'])) {
                var_dump('-------------commandType  ' . $dataArr['commandType']);
                $result = [];
                switch ($dataArr['commandType']) {
                    case ConstCode::COMMAND_TYPE_ZERO:
                        /*聊天页面心跳*/
                        $result = make(operationService::class)->getOperationPop($fd);
                        break;
                    case ConstCode::COMMAND_TYPE_EIGHTEEN:
                        /*获取客服未读消息条数*/
                        $result = make(messageService::class)->getOperationReadableCount($fd);
                        break;
                    case ConstCode::COMMAND_TYPE_FOURTEEN:
                        /*获取对话列表*/
                        $result = make(messageService::class)->getAllFriendTalkList($fd, $dataArr);
                        break;
                    case ConstCode::COMMAND_TYPE_TWELVE:
                        /*获取获取单个运营对话列表*/
                        $result = make(messageService::class)->getFriendTalkList($fd, $dataArr);
                        break;
                    case ConstCode::COMMAND_TYPE_EIGHT:
                        /*获取对话聊天记录*/
                        $result = make(messageService::class)->getMessageTalkList($fd, $dataArr);
                        break;
                    case ConstCode::COMMAND_TYPE_SIXTEEN:
                        /*联系人跳转到对话列表*/
                        $result = make(messageService::class)->getNewMessageTalk($fd, $dataArr);
                        break;
//                    case ConstCode::COMMAND_TYPE_TEN:
//                        /*切换运营者身份*/
//                        $result = make(operationService::class)->getChangeMarketUser($fd, $dataArr);
//                        break;
                    /*运营号发送消息服务端存表*/
                    case ConstCode::COMMAND_TYPE_TWO:
                        $result = make(messageService::class)->getOperationSendMessage($fd, $dataArr);
                        break;
                    /*运营号发送图片消息服务端存表*/
                    case ConstCode::COMMAND_TYPE_FOUR:
                        $result = make(messageService::class)->getOperationSendImage($fd, $dataArr);
                        break;
                }
                return $result;
            } else {
                return $this->Error(ErrorCode::ERROR, '消息解析失败' . $string);
            }
        }
        return $this->Error(ErrorCode::ERROR, '消息数据错误' . $string);
    }
}